using UnityEngine;
using System.Collections;

public class SmeltGalvanizedSteel : SmeltAlloy {
	
	Bar steelBar;
	Bar zincBar;
	
	bool hauled;
	bool haulingStarted;
	
	HaulingJob steelHauling;
	HaulingJob zincHauling;
	
	public SmeltGalvanizedSteel(int nx, int ny, int nz, Bar nzincBar, Bar nsteelBar):base(nx, ny, nz){
		
		jobType = 12;
		
		steelBar = nsteelBar;
		zincBar = nzincBar;
		
		hauled = false;
		haulingStarted = false;
		
		steelHauling = new HaulingJob(steelBar, x, y, z, this);
		zincHauling = new HaulingJob(zincBar, x, y, z, steelHauling);
		
		ItemList.steelBars.Remove(steelBar);
		ItemList.zincBars.Remove(zincBar);
		
		jobLabel = "Smelt Galvanized Steel";
		
	}
	
	public bool workOn(double workspeed, Robot robot){
		bool isDone = false;
		try {
			hauled = steelHauling.j.complete;
		} catch {
			hauled = false;
		}
		if (hauled){
			isDone =  base.workOn(workspeed, robot);
		} else {
			if (!haulingStarted){
				robot.assignJob(zincHauling, true);
				haulingStarted = true;
				Debug.Log ("Sure thing");
			}
		}
		if (isDone){
			GameObject.Destroy(zincBar.item);
			GameObject.Destroy(steelBar.item);
			GameObject obj = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("BarPrefab"));
			obj.transform.position = new Vector3(0f, 0f, 20f);
			Bar b = (Bar)obj.GetComponent("Bar");
			b.item = obj;
			b.starterate(new Brass());
			
		}
		return isDone;
	}
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
